package main.singleton;

/**
 * @Author: SerMs
 * @Date: 2024/06/17 16 43
 * @Email: 1839928782@qq.com
 * @Blog: https://serms.top
 **/
public class Singleton01 {

    // 使用静态成员变量初始化
    private static final Singleton01 instance = new Singleton01();

    private Singleton01(){}

    public static Singleton01 getInstance(){
        return instance;
    }

    public void m(){
        System.out.printf("方法");
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            // 多线程
            new Thread(()->
                    System.out.println(instance.hashCode())
                    ).start();
        }

        System.out.println("=====");
        Singleton01 demo01 = Singleton01.getInstance();
        Singleton01 demo02 = Singleton01.getInstance();
        System.out.println(demo02.equals(demo01));
        System.out.println(demo02 == demo01);
    }
}
